function hasClass(ele,cls) {
  return !!ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}


function changeTab(e, tabNum) {
  var tabHeaderWrapper = e.target.parentElement;
  var tabHeaders = tabHeaderWrapper.children;
  for(var i = 0; i < tabHeaders.length; i++) {
    (tabNum === i) ? addClass(tabHeaders[i], 'selected') : removeClass(tabHeaders[i], 'selected');
  }
  
  var tabContentWrapper = tabHeaderWrapper.nextElementSibling;
  var tabContents = tabContentWrapper.children;
  for(var i = 0; i < tabContents.length; i++) {
    (tabNum === i) ? addClass(tabContents[i], 'show') : removeClass(tabContents[i], 'show');
  }
}